"""
6、请设计一个Python抽象基类（Abstract Base Classes, ABC）案例，
并在主程序中调用展示抽象特性。
"""
from abc import ABC, abstractmethod
import math


class Shape(ABC):
    @abstractmethod#抽象方法
    def area(self):
        pass

    @abstractmethod
    def perimeter(self):
        pass


class Circle(Shape):
    def __init__(self, radius):
        self.radius = radius

    def area(self):
        return math.pi * self.radius ** 2

    def perimeter(self):
        return 2 * math.pi * self.radius


class Rectangle(Shape):
    def __init__(self, length, width):
        self.length = length
        self.width = width

    def area(self):
        return self.length * self.width

    def perimeter(self):
        return 2 * (self.length + self.width)


if __name__ == "__main__":
    circle = Circle(5)
    print(f"圆的面积：{round(circle.area(), 2)}")
    print(f"圆的周长：{round(circle.perimeter(), 2)}")

    rectangle = Rectangle(4, 6)
    print(f"矩形的面积：{rectangle.area()}")
    print(f"矩形的周长：{rectangle.perimeter()}")